<template>
	<div class="PDF">
	  <div style="height: 800px; width: auto" v-html="poHtmlCode" />
	</div>
</template>

<script>
import axios from 'axios';
	  export default{
	    name: 'PDF',
	    data(){
	      return {
	        poHtmlCode: '',
	
	      }
	    },
	    created: function(){
	      //由于vue中的axios拦截器给请求加token都得是ajax请求，所以这里必须是axios方式去请求后台打开文件的controller
	      axios.post("/api/InsertSeal/PDF/AddSeal/PDF1").then((response) => {
	        this.poHtmlCode = response.data;
	
	      }).catch(function (err) {
	        console.log(err)
	      })
	    },
	    methods:{
	      //控件中的一些常用方法都在这里调用，比如保存，打印等等
			Save() {
				pdfctrl.WebSave();
			},
							
			InsertSeal() {
				try {
					pdfctrl.zoomseal.AddSeal();
				} catch (e) {
				}
			},
			//修改密码
			ChangePsw() {
				pdfctrl.zoomseal.ShowSettingsBox();
		    },
			AfterDocumentOpened() {
					//alert(document.getElementById("PDFCtrl1").Caption);
			},
			SetBookmarks() {
					 pdfctrl.BookmarksVisible = pdfctrl.BookmarksVisible;
			},
			PrintFile() {
					 pdfctrl.ShowDialog(4);
			},
			SwitchFullScreen() {
					 pdfctrl.FullScreen = !pdfctrl.FullScreen;
			},
			SetPageReal() {
					 pdfctrl.SetPageFit(1);
			},
			SetPageFit() {
					 pdfctrl.SetPageFit(2);
			},
			SetPageWidth() {
					 pdfctrl.SetPageFit(3);
			},
			ZoomIn() {
					 pdfctrl.ZoomIn();
			},
			ZoomOut() {
					 pdfctrl.ZoomOut();
			},
			FirstPage() {
					 pdfctrl.GoToFirstPage();
			},
			PreviousPage() {
					 pdfctrl.GoToPreviousPage();
			},
			NextPage() {
					 pdfctrl.GoToNextPage();
			},
			LastPage() {
					 pdfctrl.GoToLastPage();
			},
			SetRotateRight() {
					 pdfctrl.RotateRight();
			},
			SetRotateLeft() {
					 pdfctrl.RotateLeft();
			},
			OnPDFCtrlInit() {
				pdfctrl.AddCustomToolButton("保存", "Save()", 6);
				pdfctrl.AddCustomToolButton("盖章", "InsertSeal()", 0);
				//PDF的初始化事件回调函数，您可以在这里添加自定义按钮
				if(("linux")!=(pdfctrl.ClientOS)){
					pdfctrl.AddCustomToolButton("修改密码", "ChangePsw()", 0);	
					pdfctrl.AddCustomToolButton("隐藏/显示书签", "SetBookmarks()", 0);
				}
				pdfctrl.AddCustomToolButton("打印", "PrintFile()", 6);
				pdfctrl.AddCustomToolButton("-", "", 0);
				pdfctrl.AddCustomToolButton("实际大小", "SetPageReal()", 16);
				pdfctrl.AddCustomToolButton("适合页面", "SetPageFit()", 17);
				pdfctrl.AddCustomToolButton("适合宽度", "SetPageWidth()", 18);
				pdfctrl.AddCustomToolButton("缩小", "ZoomOut()", 17);
				pdfctrl.AddCustomToolButton("放大", "ZoomIn()", 18);
				pdfctrl.AddCustomToolButton("-", "", 0);
				pdfctrl.AddCustomToolButton("首页", "FirstPage()", 8);
				pdfctrl.AddCustomToolButton("上一页", "PreviousPage()", 9);
				pdfctrl.AddCustomToolButton("下一页", "NextPage()", 10);
				pdfctrl.AddCustomToolButton("尾页", "LastPage()", 11);
				pdfctrl.AddCustomToolButton("-", "", 0);
				pdfctrl.AddCustomToolButton("向左旋转90度", "SetRotateLeft()", 12);
				pdfctrl.AddCustomToolButton("向右旋转90度", "SetRotateRight()", 13);
			},
	    },
	    mounted: function(){
	      // 将vue中的方法赋值给window
		  	window.OnPDFCtrlInit=this.OnPDFCtrlInit;
		    window.Save = this.Save;
		    window.InsertSeal = this.InsertSeal;
			window.ChangePsw = this.ChangePsw;
			window.SealList = this.SealList;
			window.AfterDocumentOpened = this.AfterDocumentOpened;
			window.SetBookmarks = this.SetBookmarks;
			window.PrintFile = this.PrintFile;
			window.SwitchFullScreen = this.SwitchFullScreen;
			window.SetPageReal = this.SetPageReal;
			window.SetPageFit = this.SetPageFit;
			window.SetPageWidth = this.SetPageWidth;
			window.ZoomIn = this.ZoomIn;
			window.ZoomOut = this.ZoomOut;
			window.FirstPage = this.FirstPage;
			window.PreviousPage = this.PreviousPage;
			window.NextPage = this.NextPage;
			window.LastPage = this.LastPage;
			window.SetRotateRight = this.SetRotateRight;
			window.SetRotateLeft = this.SetRotateLeft;
	    }
	}
</script>

